/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Utils;

import Aleatorio.Intervalo;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;


/**
 *
 * @author Sobrenombre
 */

public class Graficador {
    public static ChartPanel graficarBarras(Intervalo[] intervalo, String title, String tagX, String tagY){
        DefaultCategoryDataset dcs = new DefaultCategoryDataset();
        
        for (int i = 0; i < intervalo.length; i++) {
            dcs.addValue(intervalo[i].getFrecuencia(), "FObservada", intervalo[i].getIntervalo());
        }

        JFreeChart chart = ChartFactory.createBarChart(title,tagX, tagY, dcs, PlotOrientation.VERTICAL, true, true, true);

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setCategoryLabelPositions
	    (CategoryLabelPositions
		 .createUpRotationLabelPositions(0.5235987755982988));
        return new ChartPanel(chart, false);
    }

}